<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
    
<c:if test="${!empty messageKey}">
	<div class="alert alert-${messageType}">
	  <button type="button" class="close" data-dismiss="alert">&times;</button>
	  <p id="message">
	  	${message}
	  </p>
	</div>
</c:if>
    
<fieldset>
	<legend>Detalhes da Fatura ${invoice.month}-${invoice.year}</legend>
	
	<label>
		Limite: <strong>${invoice.limit}</strong> 
	</label>
	
	<label>
		Fatura  
		<strong>
			<c:choose>
				<c:when test="${invoice.status == 'ABERTO'}">Aberta</c:when>
				<c:when test="${invoice.status == 'FECHADO'}">Fechada</c:when>
				<c:otherwise>Paga</c:otherwise>
			</c:choose> 
		</strong> 
	</label>
	
	<label>
		Valor Total: <strong>${invoice.total}</strong>
	</label>
	
	<label>
		<c:if test="${ ! empty invoice.next }">
			<a href="${url}invoice/details/${invoice.next.id}/">Fatura ${invoice.next.month}-${invoice.next.year}</a>
		</c:if>
	</label>
	
	<label>
		<c:if test="${ ! empty invoice.previous }">
			<a href="${url}invoice/details/${invoice.previous.id}/">Fatura ${invoice.previous.month}-${invoice.previous.year}</a>
		</c:if>
	</label>
	
	<label>
		<c:if test="${ invoice.status == 'ABERTO' }">
			<a href="${url}invoice/spent/${invoice.id}/">Adicionar gasto a fatura</a>
		</c:if>
	</label>
	
</fieldset>

<section>
	<article>
		<h4>Detalhes da Fatura</h4>
		<table class="table table-striped">
			<thead>
				<tr>
					<th>Gasto</th>
					<th>Valor</th>
					<th>Data</th>
					<th>Estorno</th>
					<th>Editar</th>
					<th>Deletar</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${invoice.payments}" var="payment">
						<tr>
							<td>
								${payment.eventName}
								<c:if test="${payment.type == 'PARCELADO'}">
									- ${payment.installment}/${payment.numberOfInstallments}
								</c:if>
							</td>
							<td>${payment.value}</td>
							<td><joda:format value="${payment.purchasedDay}" style="M-" /></td>
							<td>
								<c:if test="${payment.type == 'PARCELADO' }">
									<a href="${url}payment/refund/${payment.id}/"> 
										<img src="${urlImg}refund.png" alt="Estornar" title="Estornar">
									</a> 
								</c:if>
							</td>
							<td>
								<c:if test="${payment.type == 'A VISTA' }">
									<a href="${url}payment/edit/${payment.id}/"> 
										<img src="${urlImg}edit.png" alt="Editar" title="Editar">
									</a> 
								</c:if>
							</td>
							<td>
								<c:if test="${payment.type == 'A VISTA' }">
									<a href="${url}payment/delete?spent.id=${payment.id}&spent.invoice.id=${invoice.id}"> 
										<img src="${urlImg}delete.png" alt="Deletar" title="Deletar">
									</a> 
								</c:if>
							</td>
						</tr>
				</c:forEach>
			</tbody>
		</table>
	</article>	
	<span class="clearfix">&nbsp;</span>	
</section>    
    